package com.vast.admin.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.vast.admin.entity.PlaceholderTemplate;
import com.vast.admin.service.PlaceholderTemplateService;
import com.vast.common.core.domain.entity.SysUser;
import com.vast.common.utils.SecurityUtils;
import com.vast.common.constant.MessageCode;
import com.vast.common.core.domain.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/manager/placeholderTemplate")
public class PlaceholderTemplateController {

    @Autowired
    private PlaceholderTemplateService placeholderTemplateService;

    /**
     * 分页查询
     * @param placeholderTemplate
     * @param placeholderTemplatePage
     * @return
     */
    @GetMapping("/list")
    public Result<IPage<PlaceholderTemplate>> list(PlaceholderTemplate placeholderTemplate, Page<PlaceholderTemplate> placeholderTemplatePage) {
        return new Result<>(MessageCode.SUCCESS, placeholderTemplateService.list(placeholderTemplate, placeholderTemplatePage));
    }

    /**
     * 按id获取
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result<PlaceholderTemplate> getById(@PathVariable Long id) {
        return new Result<>(MessageCode.SUCCESS, placeholderTemplateService.getBelongPlaceholderTemplateById(id));
    }

    /**
     * 保存
     * @param placeholderTemplate
     * @return
     */
    @PostMapping("/save")
    public Result<Void> save(@RequestBody PlaceholderTemplate placeholderTemplate) {
		SysUser manager = SecurityUtils.getLoginUser().getUser();
        placeholderTemplateService.savePlaceholderBelongTemplate(placeholderTemplate, manager);
        return Result.SUCCESS;
    }

    /**
     * 删除
     * @return
     */
    @DeleteMapping("/{id}")
    public Result<Void> remove(@PathVariable Long id) {
        placeholderTemplateService.removePlaceholderTemplate(id);
        return Result.SUCCESS;
    }

}
